2598. Smallest Missing Non-negative Integer After Operations

题目 2598. Smallest Missing Non-negative Integer After Operations

image-42b686aa

思路分析

image-03fa49dc

代码实现

class Solution {
    public int findSmallestInteger(int[] nums, int value) {
        int[] count = new int[value];
        for(int num:nums){
            int rem = (num % value + value) % value;
            count[rem]++;
        }

        for(int i = 0;i<nums.length;i++){
            int targetRem = i%value;
            if(count[targetRem]>0){
                count[targetRem]--;
            }else{
                return i;
            }
        }

        return nums.length;
    }
}

同类题型

视频讲解